package com.itheima.pattern.singleton.demo7;

import java.io.*;

public class Client {
    public static void main(String[] args) throws Exception {
        writeObjectFile();
        readObjectFromFile();
        readObjectFromFile();//不是同一个对象
    }

    //向文件中写数据（对象）
    public static void writeObjectFile() throws Exception {
        Singleton instance = Singleton.getInstance();
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("C:\\Users\\86186\\Desktop\\a.txt"));
        oos.writeObject(instance);
        oos.close();
    }


    //向文件中读数据（对象）
    public static void readObjectFromFile () throws Exception {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("C:\\Users\\86186\\Desktop\\a.txt"));
        Singleton o = (Singleton) ois.readObject();
        System.out.println(o);
        ois.close();
    }
}
